// GS_BPA.cpp: implementation of the CGS_BPA class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "../../Include/Swi/GS_BPA.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CGS_BPA::CGS_BPA()
{
	m_chType = 'G';
	m_chSubType = 'S';
	m_chChangeCode = ' ';

	m_dPmax = 0;
	m_dPmin = 0;
	m_dR = 0;
	m_dT1 = 0;
	m_dT2 = 0;
	m_dT3 = 0;
	m_dVELopen = 0;
	m_dVELclose = 0;
	m_dEpsilon = 0;

	m_strCardType[0] = 'G';
}

CGS_BPA::CGS_BPA(CGS_BPA &gsBPA):CUnit_BPA(gsBPA)
{
	m_dPmax = gsBPA.m_dPmax;
	m_dPmin = gsBPA.m_dPmin;
	m_dR = gsBPA.m_dR;
	m_dT1 = gsBPA.m_dT1;
	m_dT2 = gsBPA.m_dT2;
	m_dT3 = gsBPA.m_dT3;
	m_dVELopen = gsBPA.m_dVELopen;
	m_dVELclose = gsBPA.m_dVELclose;
	m_dEpsilon = gsBPA.m_dEpsilon;
}

CGS_BPA::~CGS_BPA()
{

}

bool CGS_BPA::FillEx(char *buffer)
{
	bool bResult = CUnit_BPA::FillEx(buffer);

	if (!bResult)
	{
		printf("Error in (CGS_BPA::FillEx): no basic information!\n");
		return false;
	}

	if (strlen(buffer)<17)
		return true;

	m_dPmax = StrToDouble(&buffer[16],6,1);
	if(EndOfSec(&buffer[16],6))
		return true;

	m_dPmin = StrToDouble(&buffer[22],6,1);
	if(EndOfSec(&buffer[22],6))
		return true;

	m_dR = StrToDouble(&buffer[28],5,3);
	if(EndOfSec(&buffer[28],5))
		return true;

	m_dT1 = StrToDouble(&buffer[33],5,3);
	if(EndOfSec(&buffer[33],5))
		return true;

	m_dT2 = StrToDouble(&buffer[38],5,3);
	if(EndOfSec(&buffer[38],5))
		return true;

	m_dT3 = StrToDouble(&buffer[43],5,3);
	if(EndOfSec(&buffer[43],5))
		return true;

	m_dVELopen = StrToDouble(&buffer[48],6,1);
	if(EndOfSec(&buffer[48],6))
		return true;

	m_dVELclose = StrToDouble(&buffer[54],6,1);
	if(EndOfSec(&buffer[54],6))
		return true;

	m_dEpsilon = StrToDouble(&buffer[60],6,5);
	if(EndOfSec(&buffer[60],6))
		return true;

	return true;
}

bool CGS_BPA::UpdateEx(char *buffer)
{
	bool bResult = CUnit_BPA::UpdateEx(buffer);

	if (!bResult)
	{
		printf("Error in (CGS_BPA::UpdateEx): impossible!\n");
		return false;
	}

	DoubleToStr(m_dPmax,&buffer[16],6,1);
	DoubleToStr(m_dPmin,&buffer[22],6,1);
	DoubleToStr(m_dR,&buffer[28],5,3);
	DoubleToStr(m_dT1,&buffer[33],5,3);
	DoubleToStr(m_dT2,&buffer[38],5,3);
	DoubleToStr(m_dT3,&buffer[43],5,3);
	DoubleToStr(m_dVELopen,&buffer[48],6,1);
	DoubleToStr(m_dVELclose,&buffer[54],6,1);
	DoubleToStr(m_dEpsilon,&buffer[60],6,5);

	return true;
}